package com.dk.service.impl;

import com.dk.mapper.TBookMapper;
import com.dk.pojo.TBook;
import com.dk.service.BookService;
import com.dk.vo.BookVo;
import com.dk.vo.PublisherVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private TBookMapper bookMapper;

    @Override
    public PageInfo<BookVo> selectUser(TBook book, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<BookVo> list = bookMapper.selectUser(book);
        PageInfo<BookVo> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public void addBook(TBook tBook) {
        bookMapper.insert(tBook);
    }

    @Override
    public TBook toUpdateBook(Integer bookId) {
        return bookMapper.selectByPrimaryKey(bookId);
    }

    @Override
    public void updateBook(TBook tBook) {
        bookMapper.updateByPrimaryKeySelective(tBook);
    }

    @Override
    public void deleteBook(Integer bookId) {
        bookMapper.deleteByPrimaryKey(bookId);
    }

    @Override
    public void deleteBookAll(Integer[] ids) {
        bookMapper.deleteBookAll(ids);
    }

    @Override
    public TBook getInfoById(Integer bookState) {
        return bookMapper.selectByPrimaryKey(bookState);
    }

    @Override
    public void update(TBook article) {
        bookMapper.updateByPrimaryKey(article);
    }


}
